<template>
  <div class="setting-container">
    <h4 style="margin-bottom: 15px">{{ $t('common.layout_configuration') }}</h4>
    <SelectLayoutMode />
    <el-divider />
    <h4 style="margin-bottom: 5px">{{ $t('common.function_configuration') }}</h4>
    <div v-for="(settingValue, settingName, index) in switchSettings" :key="index" class="setting-item">
      <span class="setting-name">{{ settingName }}</span>
      <el-switch
        v-model="settingValue.value"
        :disabled="!isLeft && settingName === $t('common.switch_settings.fixed_header')"
      />
    </div>
    <el-button type="danger" :icon="Refresh" @click="resetConfigLayout">{{ $t('common.reset') }}</el-button>
  </div>
</template>

<script setup>
import { watchEffect } from 'vue'
import { storeToRefs } from 'pinia'
import { useSettingsStore } from '@/store'
import { useLayoutMode } from '@/hooks/useLayoutMode'
import { resetConfigLayout } from '@/utils'
import SelectLayoutMode from './SelectLayoutMode.vue'
import { Refresh } from '@element-plus/icons-vue'
import { $t } from '@/languages/index'
const { isLeft } = useLayoutMode()
const settingsStore = useSettingsStore()

/** 使用 storeToRefs 将提取的属性保持其响应性 */
const {
  showTagsView,
  showLogo,
  fixedHeader,
  showFooter,
  showNotify,
  showThemeSwitch,
  showScreenfull,
  showSearchMenu,
  cacheTagsView,
  showWatermark,
  showGreyMode,
  showColorWeakness
} = storeToRefs(settingsStore)

/** 定义 switch 设置项 */
const switchSettings = computed(() => ({
  [$t('common.switch_settings.show_tags_view')]: showTagsView,
  [$t('common.switch_settings.show_logo')]: showLogo,
  [$t('common.switch_settings.fixed_header')]: fixedHeader,
  [$t('common.switch_settings.show_footer')]: showFooter,
  [$t('common.switch_settings.show_notify')]: showNotify,
  [$t('common.switch_settings.show_theme_switch')]: showThemeSwitch,
  [$t('common.switch_settings.show_screenfull')]: showScreenfull,
  [$t('common.switch_settings.show_search')]: showSearchMenu,
  [$t('common.switch_settings.cache_tags_view')]: cacheTagsView,
  [$t('common.switch_settings.show_watermark')]: showWatermark,
  [$t('common.switch_settings.show_grey_mode')]: showGreyMode,
  [$t('common.switch_settings.show_color_weakness')]: showColorWeakness
}))

/** 非左侧模式时，Header 都是 fixed 布局 */
watchEffect(() => {
  !isLeft.value && (fixedHeader.value = true)
})
</script>

<style lang="scss" scoped>
@use '@/styles/mixins.scss';

.setting-container {
  padding: 20px;
  .setting-item {
    font-size: 14px;
    color: var(--el-text-color-regular);
    padding: 5px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .setting-name {
      @extend %ellipsis;
    }
  }
  .el-button {
    margin-top: 40px;
    width: 100%;
  }
}
</style>
